//
//  FbeeCommitBtn.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/6.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "FbeeCommitBtn.h"

@interface FbeeCommitBtn()
{
    UIButton *btn;
    UIImageView *bg;
    
    FbeeCommitBlock callback;
}

@end

@implementation FbeeCommitBtn

-(instancetype)initWithTitle:(NSString *)title
{
    self = [super initWithFrame:CGRectMake(0, 0, 280*UISCALE, 70*UISCALE)];

    if (self) {
        
        btn = [UIButton makeButton:^(TTButtonExtend *make) {
            make.addBackGoundImage([UIImage imageNamed:@"common_commitbtn"],UIControlStateNormal);
            make.setFrame(CGRectMake(0, 0, 280*UISCALE, 50*UISCALE));
            make.addTitle(title).addTitleColor(UIColorFromRGB(0x744A05),UIControlStateNormal).addFont([UIFont systemFontOfSize:16.0f]);
            make.addTarget(self,@selector(commit));
            make.clipsToBounds = YES;
            make.layer.cornerRadius = (50*UISCALE)/2;
        }];
        
        bg = [[UIImageView alloc] initWithFrame:CGRectMake(-24, -10, 328*UISCALE, 101*UISCALE)];
        bg.image = [UIImage imageNamed:@"common_commitbtn_shadow"];
        
        [self addSubview:bg];
        [self addSubview:btn];
    }
    
    return self;
}

-(void)setBtnFrame:(CGRect)frame
{
    self.frame = frame;
    
    //先算放大比例
    float scaleW = frame.size.width/280;
    float scaleH = frame.size.height/70;
    
    
    btn.width = btn.width*scaleW;
    btn.height = btn.height*scaleH;
    btn.layer.cornerRadius = btn.height/2;
    
    bg.top = bg.top*scaleH;
    bg.left = bg.left*scaleW;
    bg.width = bg.width*scaleW;
    bg.height = bg.height *scaleH;
    
    
}

-(void)onClick:(FbeeCommitBlock)block
{
    callback = block;
}

-(void)commit
{
    if (callback) {
        callback();
    }
    
}

@end
